package com.nondo.rdp.finance.repository;

import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.core.common.StatusConstant;
import com.nondo.rdp.finance.domain.UserAuth;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;
import java.util.Optional;

/**
 * 用户认证接口
 *
 * @author slacrey
 * @version 2013-01-15
 */
public interface UserAuthRepository extends JpaRepository<UserAuth, Long>, JpaSpecificationExecutor<UserAuth> {
    Optional<UserAuth> findByUser(User user);

    UserAuth save(UserAuth userAuth);

    @Modifying
    @Query("update User set delFlag='" + StatusConstant.DEL_FLAG_DELETE + "' where id = ?1")
    int deleteById(Long id);

    @Query("select u from User u where delFlag = '" + StatusConstant.DEL_FLAG_NORMAL + "'")
    List<UserAuth> getAll();

}